package com.zl.learning.arithmetic.my;

import java.util.Arrays;

public class ShellSort {
    //    private static int[] a = new Random().ints(0, 100).limit(7).toArray();
    private static int[] a = {31, 28, 63, 12, 27, 55, 31, 33, 0};

    /**
     * 每一趟内循环，选出最小的。然后交换
     */
    private static void shellSort(int[] a) {
        for (int gap = a.length / 2; gap > 0; gap /= 2) {
            for (int i = 0; i < a.length; i++) {
                for (int j = i - gap; j >= 0; j -= gap) {
                    if (a[j] > a[j + gap]) {
                        int tmp = a[j];
                        a[j] = a[j + gap];
                        a[j + gap] = tmp;
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(a));
        shellSort(a);
        System.out.println(Arrays.toString(a));
    }
}
